< previous page page_378 next page >

Page 378
Procedural Data Usage
As an example of procedural coding, think of how you would have to draw a form if forms were not objects. Remember that a form has many properties in its properties sheet. To accomplish this using procedural coding, you have to pass all the properties as parameters to a procedure to tell the form how to draw itself. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Call DisplayEmpForm(1, 1, 1025, 2045, _
         1, 1, 0, &H000000, &HF00000, "Sans Serif", _
         True, False, etc., etc., etc.)
In the DisplayEmpForm procedure call, you can see each of the different properties is being passed as a data value. There are several problems with this scenario. First, you must remember what each parameter is and what position to pass it in. Second, the line of source code is very long. Third, theres no way to initialize the function so the data values are initialized (constructor). Fourth, if you want to change, add, or delete any parameters, youll break every line of code that calls this function (unless you can set up optional parameters). As you can see, there are a lot of problems with the traditional approach to programming applications.
OOP's Data Usage
A form is an object that set defaults for most of its properties in its constructor event. You only have to change the properties you need to override and then invoke a method to display the form:
9f31265bb40b592b1929e18a47ab28e5.gif
frmEmployee.Top = 10
frmEmployee.Left = 10
frmEmployee.Show
The object takes care of all the details internally concerning how to display itself. Additionally, if you need to add more functionality, you simply add a new property and set a default for it in the constructor. This does not break any existing code, but any object that needs this new property may now use it. Also, if this new property adds something to the interface of the object, every object now gets this new change without any other source code changes!
Function/Method Naming
Another advantage of OOP is polymorphism (the ability for each object to have the same method names but perform different actions based on those methods). For example, an Employee form is different from a TimeSheet form, but each has a

 
< previous page page_378 next page >

If you like this book, buy it!